--
-- Author: ping.wang
-- Date: 2019-06-26 11:54:48
--
-- RewardHeroTreasureBuyView
--

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)
--购买界面和说明界面为同一文件
ClassRef.VIEW_ROOT_RES = Res.RewardHeroTreasureBuyScene

--data{type,uid,price,iconPath,itemId}
function ClassRef:init()
    self._ui.Button_close:addClickEventListener(function()
        self:closeView()
    end)

    if self._data.type == 1 then
        self._ui.Panel_content_1:setVisible(true)
        self._ui.Panel_content_2:setVisible(false)
        self._ui.Panel_content_1:findChild("Button"):addClickEventListener(
            function()
                --前往每周追求
                executeFunc(self._onOperate, "gotoWeekWork")
            end
        )
    else
        self._ui.Panel_content_1:setVisible(false)
        self._ui.Panel_content_2:setVisible(true)

        self._ui.Panel_content_2:findChild("Panel_buy/Button"):addClickEventListener(
            function()
                --购买
                if UD:getItemAmountByTid(self._data.itemId) >= self._data.price then

                    executeFunc(self._onOperate,"buyGoldenHeroTreasure", self._data.uid)
                else
                    if UIHandler:isFunctionOpen(Constant.FUNC_TYPE_SHOP) then
                        local goShopDialog = display.newConfirmDialog( L("levelpromotion7"),
                            function() -- 确定
                                app:sendMsg("MallController", "buyGameRes", Constant.ShopDraw_ItemId)
                            end)
                        UIHandler:addPopDialog( goShopDialog )
                    end
                end

            end
        )

        self._ui.Panel_content_2:findChild("Panel_buy/icon"):loadTexture(self._data.iconPath)
        self._ui.Panel_content_2:findChild("Panel_buy/num"):setString(self._data.price)
    end
end

return ClassRef
